<template>
  <div class="nav">
<!--    <span class="tag">统计报表</span> <el-button @click="test">test</el-button>-->
    <div class="box">
      <div v-for="(item,index) in exam" :key="index" class="ques">
        <div style="height: 80px">
          <span style="margin-right: 10px">Q.{{index + 1}}</span>
          <span>{{item.questioncontent}}</span>
          <div v-for="(ite,ind) in item.answer" :key="ind" class="answ">
            <div v-if="ite.istrue === 'True'">(正确答案：{{ite.answer}})</div>
          </div>
        </div>

        <div v-if="item.questiontype === 1 || item.questiontype === 2 || item.questiontype === 3">
          <div class="wrapper">
            <div class="roseChart" style="width: 600px;height:400px;margin-left: 250px"></div>
          </div>
            <el-table :data="tableData[index].resData" style="width: 70%;margin-left: 150px" :header-cell-style="{background:'#eef1f6'}">
              <el-table-column prop="name" label="选项内容" width="600">
              </el-table-column>
              <el-table-column prop="value" label="回复情况" align="center" width="250">
              </el-table-column>
            </el-table>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
export default {
  name: "StatisForm",
  props: ["msg"],
  data() {
    return {
      // tableData: [
      //    [
      //     {name: '第一题的选项一', value: '70%'},
      //     {name: '第一题的选项二', value: '80%'}
      //     ],
      //    [
      //     {name: '第二题的选项一', value: '70%'},
      //     {name: '第二题的选项二', value: '80%'}
      //     ]
      // ],
      tableData: [],
      exam: [],

      list: [],
      // list:[
      //   {
      //     resData: [
      //       {name: '选项一', value: 12},
      //       {name: '选项二', value: 18},
      //       {name: '选项三', value: 8},
      //       {name: '选项四', value: 10},
      //       {name: '选项五', value: 10},
      //     ],
      //   }, {
      //     resData: [
      //       {name: '选项一', value: 12},
      //       {name: '选项二', value: 18},
      //       {name: '选项三', value: 8},
      //       {name: '选项四', value: 10},
      //     ],
      //   },{
      //     resData:[
      //       {name:'选项一',value:12},
      //       {name:'选项二',value:18},
      //       {name:'选项三',value:8},
      //       {name:'选项四',value:10},
      //     ]
      //   }],

    }
  },
  computed: {
    getReport(){
      return this.$store.state.reportDate
    }
  },
  watch: {
    getReport(){
      // this.list = this.$store.state.reportDate.reportDate.data.resData;
      this.tableData = this.$store.state.reportDate.reportDate.data.resData;

    }
  },
  created() {
    localStorage.getItem("testMsg") && this.$store.replaceState(Object.assign(this.$store.state,JSON.parse(localStorage.getItem("testMsg"))));
    window.addEventListener("beforeunload",()=>{
      localStorage.setItem("testMsg",JSON.stringify(this.$store.state))
    })
  },
  methods: {
    // test() {
    //   console.log(this.exam)
    // },
    numChange(){
      for (let i in this.tableData){
        for (let j in this.tableData[i].resData){
          let num = this.tableData[i].resData[j].value
          this.tableData[i].resData[j].value = num + "%"
        }
      }
    },
    getExam(){
      for (let i in this.msg.currentExam){
        if (this.msg.currentExam[i].questiontype !== 5){
          this.exam.push(this.msg.currentExam[i])
        }
      }
    },
    myEcharts() {
      let roseCharts = document.getElementsByClassName('roseChart');
      for (let i in roseCharts) {
        let myChart = this.$echarts.init(roseCharts[i]);
        let option = {
          series: [
            {
              name: '访问来源',
              type: 'pie',
              radius: '55%',
              // roseType: 'angle',
              data: this.$store.state.reportDate.reportDate.data.resData[i].resData,
              label: {
                formatter: params => {//●▅
                  return (
                      '{icon|●}{name|' + params.name + '}{value|' +
                      params.value + '}' + '%'
                  );
                },
                rich: {
                  icon: {
                    fontSize: 16,
                    color: '#B3C0D1'
                  },
                  name: {
                    fontSize: 16,
                    padding: [0, 10, 0, 4],
                    color: '#484848'
                  },
                  value: {
                    fontSize: 16,
                    color: '#484848'
                  }
                },
              }

            }
          ]
        };
        myChart.setOption(option);
      }
    },

  },

  mounted() {
    this.getExam();

    setTimeout(() => {
      this.myEcharts()
    },1000)
  }


}
</script>

<style scoped>
.nav {
  height: 100%;
  width: 1300px;
  margin: 0 auto;
}
.nav .tag {
  border-left: 3px solid #B3C0D1;
  padding-left: 5px;
  color: #484848;
  font-size: 17px;
}
.nav .box {
  width: 100%;
  background: #fff;
  margin: 15px 0;
  box-shadow: 0 2px 4px 0 #ecebeb;
  border-radius: 4px;
  padding: 25px 25px;
  box-sizing: border-box;
  color: #707070;
}
.nav .box .ques{
  border-bottom: 1px solid #B3C0D1;
  padding: 20px 5px;
}
.nav .box .ques .answ {
  height: 30px;
  width: 200px;
  margin-left: 30px;
  margin-top: 20px;
  color: indianred;
  /*background-color: #B3C0D1;*/
}
.nav .box .ques .title {
  margin-bottom: 10px;
}

.wrapper {
  width: 900px;
  height: 400px;
}
</style>
